package com.ds.robot.assistant.controller.api;

import cn.hutool.core.comparator.PinyinComparator;
import com.google.common.cache.LoadingCache;
import com.ds.robot.assistant.common.R;
import com.ds.robot.assistant.service.EmpInfoService;
import com.ds.robot.assistant.vo.resp.EmpVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 作用：
 *
 * @author WeiShaoying
 * 
 */
@RestController
@RequestMapping("/api/emp")
@Slf4j
public class EmpController {

    @Autowired
    private EmpInfoService empInfoService;

    @Resource
    private LoadingCache<String, String> userCache;

    @RequestMapping("/queryAll")
    public R queryAllEmp() {
        List<EmpVO> voList = userCache.asMap().entrySet().stream().map(entry -> new EmpVO(entry.getKey(), entry.getValue()))
                // .sorted(Comparator.comparing(EmpVO::getName, new PinyinComparator()))
                .sorted((o1, o2) -> new PinyinComparator().compare(o2.getName(), o1.getName()))
                .collect(Collectors.toList());
        return R.ok().put("data", voList);
    }

}
